package com.socket;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @author Yancy
 * @program springioctest
 * @create 2021-01-17
 */
public class LoginClient {
  public static void main(String[] args) throws IOException {
    // 创建一个Socket
    Socket socket = new Socket(InetAddress.getLocalHost(), 8888);
    // 发送登录信息
    OutputStream os = socket.getOutputStream();
    DataOutputStream dos = new DataOutputStream(os);
    dos.writeUTF("userName=lyx&password=123");

    // 接收服务器
    InputStream is = socket.getInputStream();
    DataInputStream dis = new DataInputStream(is);
    String result = dis.readUTF();
    System.out.println(result);
    // 关闭资源
    dis.close();
    is.close();
    dos.close();
    os.close();
    socket.close();
  }
}
